﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace Common.Util
{
   public class IPHelper
    {
       /// <summary>
       /// 获取本机IP地址
       /// </summary>
       /// <returns></returns>
       public static string GetIPAddress()
       {
           try
           {
               string ipAddressStr = "";
               IPHostEntry entry = Dns.GetHostEntry("");
               foreach (IPAddress address in entry.AddressList)
               {
                   if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                   {
                       ipAddressStr = address.ToString();
                       break;
                       //Console.WriteLine(ipAddressStr);
                   }
               }
               return ipAddressStr;
           }
           catch
           {
               return "";
           }
       }
    }
}
